# -*- coding: utf-8 -*-

# ***************************************************************
# 续费页面计算函数
# ***************************************************************
def calc_num(actIncome, Rebate):
    calc_Market_price    = actIncome * Rebate               # 计算市场价
    calc_cost            = calc_Market_price * 0.7          #计算成本
    calc_tax             = actIncome * 0.06                 #计算税金
    calc_total_profit    = actIncome - calc_cost - calc_tax # 计算总利润
    calc_sales_profit    = calc_total_profit * 0.6          # 计算销售利润
    calc_customer_profit = calc_total_profit * 0.4          #计算客服利润

    return [round(calc_Market_price,5),
            round(calc_cost,5),
            round(calc_tax,5),
            round(calc_total_profit,5),
            round(calc_sales_profit,5),
            round(calc_customer_profit,5)
            ]
# ---------------------------------------------------------------

# ***************************************************************
# 续费页面计算函数
# ***************************************************************
def glob_calc(actIncome):
    Market_price = actIncome * 1.4  # 计算市场价
    adj = actIncome * 0.06          # 计算调整项
    cost = actIncome - adj          # 计算成本

    return [
        round(Market_price, 5),
        round(adj, 5),
        round(cost, 5)
           ]
# ---------------------------------------------------------------

# ***************************************************************
# 点拾点趣续费页面计算函数
# ***************************************************************
def pick_calc(actIncome):
    Market_price = actIncome * 1.35 #计算市场价
    other = actIncome * 0.04        #计算其他
    tax = actIncome * 0.06          #计算税金
    cost = actIncome - other - tax  #计算成本
    adj = other + tax               #计算调整项

    return [
        round(Market_price, 5),
        round(other, 5),
        round(tax, 5),
        round(cost, 5),
        round(adj, 5),
    ]

# ---------------------------------------------------------------

# ***************************************************************
# 乐嗨思享时光续费页面计算函数
# ***************************************************************
def happy_calc(actIncome):
    Market_price = actIncome * 1.35  # 计算市场价
    tax = actIncome * 0.06  # 计算税金
    cost = actIncome - tax  # 计算成本

    return [
        round(Market_price, 5),
        round(tax, 5),
        round(cost, 5),
    ]
# ---------------------------------------------------------------

def change_str_float_or_int(str):
    '''将字符串转换为int型或者是float型
    如果被转换成了int，则返回['True','int',value]
    如果被转换成了float，则返回['True','float',value]
    如果出错(或长度为0)则返回['False'],
    '''
    if len(str) == 0:
        return ['False']

    try:
        tmp = int(str)
    except ValueError:
        try:
            tmp = float(str)
        except ValueError:
            return ['False']
        return ['True','float',tmp]
    return ['True','int',tmp]

def GetNumbit(num):
    '''返回int数据位数'''
    temp = int(num)
    str_num = str(temp)
    return len(str_num)


def GetColor(num):
    '''千 -- 蓝、
       万 -- 绿、
       十万 -- 黄、
       百万 -- 红、
       千万 -- 紫'''
    temp = GetNumbit(num)
    if temp == 4:
        return 'color:rgb(0,0,255)'
    elif temp == 5:
        return 'color:rgb(178,223,238)'
    elif temp == 6:
        return 'color:rgb(85,107,47)'
    elif temp == 7:
        return 'color:rgb(127,255,0)'
    elif temp == 8:
        return 'color:rgb(238,44,44)'
    else:
        return 'color:black'

if __name__ == '__main__':
    a = '1234'
    b = '123.456'
    c = 'acb'
    d = ''
    print(change_str_float_or_int(a))
    print(change_str_float_or_int(b))
    print(change_str_float_or_int(c))
    print(change_str_float_or_int(d))